package sk.mucha.tracking.classes;

import org.apache.wicket.Component;
import org.apache.wicket.Page;
import org.apache.wicket.RestartResponseAtInterceptPageException;
import org.apache.wicket.Session;
import org.apache.wicket.authorization.Action;
import org.apache.wicket.authorization.IAuthorizationStrategy;

import sk.mucha.tracking.LoginPage;
import sk.mucha.tracking.MySession;

public class AuthStrategy implements IAuthorizationStrategy {

	public boolean isActionAuthorized(Component component, Action action) {
		return true;
	}

	public <T extends Component> boolean isInstantiationAuthorized(Class<T> componentClass) {
		if(!Page.class.isAssignableFrom(componentClass)) {
			return true;
		}
		
//		if(!SecurePage.class.isAssignableFrom(componentClass)) {
//			return true;
//		}
		
		if(LoginPage.class.isAssignableFrom(componentClass)) {
			return true;
		}
		
		if(MySession.get().getUserEmail()==null) {
			throw new RestartResponseAtInterceptPageException(LoginPage.class);
		}
		return true;
	}

}
